package edison.utils;

import java.util.ArrayList;
import java.util.List;

import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.PropertyDefinition;

import edison.persistence.NodeBean;
import edison.persistence.NodeDefinitionBean;
import edison.persistence.PropertyBean;
import edison.persistence.PropertyDefinitionBean;

public abstract class Converter {

	public static Property toProperty(PropertyBean bean) {
		return null;
	}

	public static Node toNode(NodeBean bean) {
		return null;
	}

	public static List<String> toList(String[] strings) {
		if (strings == null)
			return null;
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < strings.length; i++) {
			list.add(strings[i]);
		}

		return list;
	}
	
	public static String[] toArray(List<String> list){
		if (list == null)
			return null;
		String[] strings=new String[list.size()];
		for (int i = 0; i < strings.length; i++) {
			strings[i]=list.get(i);
		}

		return strings;

	}

	public static List<PropertyDefinitionBean> toPropertyDefinitionBeans(PropertyDefinition[] propertyDefinitions) {
		if (propertyDefinitions == null)
			return null;
		List<PropertyDefinitionBean> propertyDefinitionBeans = new ArrayList<PropertyDefinitionBean>();
		for (int i = 0; i < propertyDefinitions.length; i++) {
			propertyDefinitionBeans.add(new PropertyDefinitionBean(propertyDefinitions[i]));
		}
		return propertyDefinitionBeans;
	}

	public static List<NodeDefinitionBean> toNodeDefinitionBeans(NodeDefinition[] nodeDefinitions) {
		if (nodeDefinitions == null)
			return null;
		List<NodeDefinitionBean> nodeDefinitionBeans = new ArrayList<NodeDefinitionBean>();
		for (int i = 0; i < nodeDefinitions.length; i++) {
			nodeDefinitionBeans.add(new NodeDefinitionBean(nodeDefinitions[i]));
		}
		return nodeDefinitionBeans;
	}

}
